package com.spc.car.data.service.org.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spc.car.common.utils.StringUtils;
import com.spc.car.data.entity.org.OrgRewPun;
import com.spc.car.data.mapper.org.OrgRewPunMapper;
import com.spc.car.data.domain.org.po.GetOrgRewPunListPO;
import com.spc.car.data.service.org.OrgRewPunService;
import com.spc.car.data.domain.org.vo.OrgRewPunListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 机构奖惩记录表 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-03-27
 */
@Service
public class OrgRewPunServiceImpl extends ServiceImpl<OrgRewPunMapper, OrgRewPun> implements OrgRewPunService {

    @Override
    public Page<OrgRewPunListVO> selectOrgRewPunList(GetOrgRewPunListPO getOrgRewPunListPO) {
        Page page = page(getOrgRewPunListPO.getPage(), new QueryWrapper<OrgRewPun>()
                .eq(null != getOrgRewPunListPO.getId(), "id" , getOrgRewPunListPO.getId())
                .like(StringUtils.isNotBlank(getOrgRewPunListPO.getOrgCode()), "org_code" , getOrgRewPunListPO.getOrgCode())
                .like(StringUtils.isNotBlank(getOrgRewPunListPO.getContent()), "content", getOrgRewPunListPO.getContent())
                .like(StringUtils.isNotBlank(getOrgRewPunListPO.getType()), "type", getOrgRewPunListPO.getType())
        );
        if (page.getRecords().isEmpty()){
            return page;
        }
        List<OrgRewPunListVO> orgRewPunListVOS = new ArrayList<>();
        page.getRecords().stream().forEach(anOrgRewPun ->{
            OrgRewPunListVO orgRewPunListVo = new OrgRewPunListVO();
            BeanUtils.copyProperties(anOrgRewPun, orgRewPunListVo);
            orgRewPunListVOS.add(orgRewPunListVo);
        });
        return page.setRecords(orgRewPunListVOS);
    }
}
